

###################################################################

  Table 6. Comparisons of Test Statistics and Fit Indices

###################################################################

library(lavaan)
library(foreign)


ess<-read.csv("/Users/bv533/Dropbox/LM-Test/Empirical Application/ESS/ESS.csv")

ess<-as.data.frame(ess)

DE=ess[ess$cntry=="DE",]


####################

  Cleaning data

###################


#1 Equality

DE$ipeqopt
DE$ipeqopt[DE$ipeqopt==7]<-NA
DE$ipeqopt[DE$ipeqopt==8]<-NA
DE$ipeqopt[DE$ipeqopt==9]<-NA

#2 Understand

DE$ipudrst
DE$ipudrst[DE$ipudrst==7]<-NA
DE$ipudrst[DE$ipudrst==8]<-NA
DE$ipudrst[DE$ipudrst==9]<-NA


#3 Environment

DE$impenv
DE$impenv[DE$impenv==7]<-NA
DE$impenv[DE$impenv==8]<-NA
DE$impenv[DE$impenv==9]<-NA

#4 Help others

DE$iphlppl
DE$iphlppl[DE$iphlppl==7]<-NA
DE$iphlppl[DE$iphlppl==8]<-NA
DE$iphlppl[DE$iphlppl==9]<-NA


#5 Loyalty

DE$iplylfr
DE$iplylfr[DE$iplylfr==7]<-NA
DE$iplylfr[DE$iplylfr==8]<-NA
DE$iplylfr[DE$iplylfr==9]<-NA



#6 Modesty
DE$ipmodst
DE$ipmodst[DE$ipmodst==7]<-NA
DE$ipmodst[DE$ipmodst==8]<-NA
DE$ipmodst[DE$ipmodst==9]<-NA


#7 Tradition
DE$imptrad
DE$imptrad[DE$imptrad==7]<-NA
DE$imptrad[DE$imptrad==8]<-NA
DE$imptrad[DE$imptrad==9]<-NA


#8 Rules
DE$ipfrule
DE$ipfrule[DE$ipfrule==7]<-NA
DE$ipfrule[DE$ipfrule==8]<-NA
DE$ipfrule[DE$ipfrule==9]<-NA


#9 Propriety

DE$ipbhprp
DE$ipbhprp[DE$ipbhprp==7]<-NA
DE$ipbhprp[DE$ipbhprp==8]<-NA
DE$ipbhprp[DE$ipbhprp==9]<-NA


#10 Security
DE$impsafe
DE$impsafe[DE$impsafe == 7]<-NA
DE$impsafe[DE$impsafe == 8]<-NA
DE$impsafe[DE$impsafe == 9]<-NA

#11 Strong Government

DE$ipstrgv
DE$ipstrgv[DE$ipstrgv==7]<-NA
DE$ipstrgv[DE$ipstrgv==8]<-NA
DE$ipstrgv[DE$ipstrgv==9]<-NA


#12 Race
DE$imdfetn
DE$imdfetn[DE$imdfetn ==7]<-NA
DE$imdfetn[DE$imdfetn ==8]<-NA
DE$imdfetn[DE$imdfetn ==9]<-NA


#13 EU poor

DE$eimpcnt
DE$eimpcnt[DE$eimpcnt==7]<-NA
DE$eimpcnt[DE$eimpcnt==8]<-NA
DE$eimpcnt[DE$eimpcnt==9]<-NA

#14 Richer

DE$eimrcnt
DE$eimrcnt[DE$eimrcnt== 7]<-NA
DE$eimrcnt[DE$eimrcnt== 8]<-NA
DE$eimrcnt[DE$eimrcnt== 9]<-NA


#15. poor

DE$imrsprc
DE$imrsprc[DE$imrsprc==7]<-NA
DE$imrsprc[DE$imrsprc==8]<-NA
DE$imrsprc[DE$imrsprc==9]<-NA

#16 Qualify: Education

DE$qfimedu
DE$qfimedu[DE$qfimedu ==77]<-NA
DE$qfimedu[DE$qfimedu ==88]<-NA
DE$qfimedu[DE$qfimedu ==99]<-NA


#17 Qaulify: Work Skill

DE$qfimwsk
DE$qfimwsk[DE$qfimwsk==77]<-NA
DE$qfimwsk[DE$qfimwsk==88]<-NA
DE$qfimwsk[DE$qfimwsk==99]<-NA


######################################################################


############################

  Run the original model

############################



## We ramdonly choose 500 samples

set.seed(123)
DE2 <- DE[sample(nrow(DE), 500), ]

original<-'

f1=~ ipeqopt + ipudrst + impenv + iphlppl + iplylfr

f2=~ ipmodst + imptrad + ipfrule + ipbhprp + impsafe + ipstrgv

f3=~imdfetn + eimpcnt + eimrcnt + imrsprc

f4=~ qfimedu + qfimwsk

#### missing f2~~f3, and f3~~f4

f1=~f4

f2=~f4
f1~~f2

f1=~f3

 '


## we need to include f1=~f3 to activate it

fit_original <- cfa(model = original, data=DE2, int.ov.free = FALSE, std.lv = FALSE, estimator = "ML")

fitMeasures(fit_original,c("chisq", "df", "pvalue", "nfi", "tli", "cfi", "rmsea"))


### Here it print out the test statistics and fit indices in Table 6 of the original model. 



## We add the improved LM test suggested parameters to the original model. 
modified_model<-'

f1=~ ipeqopt + ipudrst + impenv + iphlppl + iplylfr

f2=~ ipmodst + imptrad + ipfrule + ipbhprp + impsafe + ipstrgv + eimrcnt

f3=~imdfetn + eimpcnt + eimrcnt + imrsprc + ipudrst

f4=~ qfimedu + qfimwsk

#### missing f2~~f3, and f3~~f4

f1=~f4
f2=~f4
f1~~f2
f1=~f3
f2=~f3
ipfrule ~~ ipbhprp
f3~~f4
ipeqopt~~imptrad
 '

fit_modified <- cfa(model = modified_model, data=DE2, int.ov.free = FALSE, std.lv = FALSE, estimator = "ML")
fitMeasures(fit_modified, c("chisq", "df", "pvalue", "nfi", "tli", "cfi", "rmsea"))

#### This print out the test statistics and fit indices of the modified model




#########. The End

######### All results match the manuscript, 12/7/24



